package com.rovinj_server.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;


import com.rovinj_server.R;
import com.rovinj_server.entity.InventoryTaskSub;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


public class SameAAdapter extends BaseAdapter{

	private Context mContext;

	private List<InventoryTaskSub> mListDataBean = new ArrayList<>();
	private HashMap<Integer,Boolean> isSelected;
	public int showCount = 20;
	public SameAAdapter(Context context, List<InventoryTaskSub> mListDataBean){
		this.mContext = context;
		this.mListDataBean = mListDataBean;
		isSelected = new HashMap<Integer, Boolean>();
		initDate();
	}

	// 初始化isSelected的数据
	private void initDate(){
		for(int i=0; i<mListDataBean.size();i++) {
			getIsSelected().put(i,false);
		}
	}

	public HashMap<Integer,Boolean> getIsSelected() {
		return isSelected;
	}

	public  void setIsSelected(HashMap<Integer,Boolean> isSelected) {
		this.isSelected = isSelected;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
//		return mList.size();

		return  showCount > mListDataBean.size() ? mListDataBean.size() : showCount;
	}

	@Override
	public Object getItem(int i) {
		// TODO Auto-generated method stub
		return mListDataBean.get(i);
	}

	@Override
	public long getItemId(int i) {
		// TODO Auto-generated method stub
		return mListDataBean.size();
	}

	@Override
	public View getView(int i, View convertView, ViewGroup viewgroup) {
		  List<InventoryTaskSub> list = new ArrayList<>();
		if (mListDataBean.size() > showCount){
			list = mListDataBean.subList(0,showCount);
		}else {
			list = mListDataBean;
		}

		ViewHolder holder;
		if (convertView !=null) {
			holder = (ViewHolder) convertView.getTag();
		} else {

			holder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(R.layout.adapter_same_a, viewgroup, false);
			holder. indepotid = (TextView) convertView.findViewById(R.id.gr_indepotid);
			holder.actualQty = (TextView) convertView.findViewById(R.id.gr_actualQty);
			holder.	qty = (TextView) convertView.findViewById(R.id.gr_qty);
			holder.	supplierName = (TextView) convertView.findViewById(R.id.gr_supplier_name);
			holder.	depotName = (TextView) convertView.findViewById(R.id.gr_depot_name);
			holder.	updateDate = (TextView) convertView.findViewById(R.id.gr_updateDate);
			holder.cb = (CheckBox) convertView.findViewById(R.id.chec_kbox);
			convertView.setTag(holder);
			AutoUtils.autoSize(convertView);
		}

		InventoryTaskSub dataBean = mListDataBean.get(i);
		holder.indepotid.setText(dataBean.getBarode());
//       int actualQty = dataBean.getIndepotsubList().get(position).getActualQty();
//      int qty = dataBean.getIndepotsubList().get( A).getQty();
       // holder.actualQty.setText(dataBean.getSupplier().getCode());
//        holder.qty.setText(qty+"");
		//holder.supplierName.setText(dataBean.getSupplier().getName());
	//	holder.depotName.setText(dataBean.getDepot().getName());
	//	holder.updateDate.setText(dataBean.getUpdateDate());
		viewgroup.setBackgroundResource(R.drawable.usermainpage_bg_center);
		holder.cb.setChecked(getIsSelected().get(i));
		return convertView;
	}

	public void setListDataBean(List<InventoryTaskSub> listDataBean) {
		mListDataBean = listDataBean;
	}

	public static class ViewHolder {


		public TextView indepotid;//收货单号
		public TextView qty;//应该收数量
		public	TextView actualQty;//已收数量
		public 	TextView supplierName;//供应商名字
		public	TextView depotName;//仓库名字
		public	TextView updateDate;//时间
		public CheckBox cb;
	}

}
